import Vue from 'vue'
import Vuex from 'vuex'
import { postLogin } from '@/api/login.js'
import { Storage } from '@/utils/Storage.js'
Vue.use(Vuex)

export default new Vuex.Store({
  // strict: true,
  state: {
    token: Storage.get('token') || '',
    refresh_token: Storage.get('refresh_token') || ''
  },
  mutations: {
    setToken (state, token) {
      Storage.set('token', token)
      state.token = token

    },
    setRefresh_token (state, refresh_token) {
      Storage.set('refresh_token', refresh_token)
      state.refresh_token = refresh_token
    }
  },
  actions: {
    // 存放token
    async asyncAction (store, obj) {
      const req = await postLogin(obj)
      // console.log(req);
      store.commit('setToken', req.data.data.token)
      store.commit('setRefresh_token', req.data.data.refresh_token)
      // {
      //   token: req.data.data.token,
      //   refresh_token: req.data.data.refresh_token
      // }
    }
  },
  modules: {
  }
})
